﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.DynamicData;
using System.ComponentModel;
using System.Data.Objects.DataClasses;

namespace Fatec.ControleEstoque.Interface.DynamicData.FieldTemplates
{
    public partial class ManyToMany : FieldTemplateUserControl
    {
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);

            // Get the real entity from the wrapper
            object entity = ((ICustomTypeDescriptor)Row).GetPropertyOwner(null);

            // Get the collection and make sure it's loaded
            var entityCollection = (RelatedEnd)Column.EntityTypeProperty.GetValue(entity, null);
            entityCollection.Load();

            // Bind the repeater to the list of children entities
            Repeater1.DataSource = entityCollection;
            Repeater1.DataBind();
        }

        public override Control DataControl { get { return Repeater1; } }
    }
}